//
//  PlaceNet.m
//  SportSocial
//
//  Created by yull on 15/1/21.
//  Copyright (c) 2015年 yull. All rights reserved.
//

#import "PlaceNet.h"

@implementation PlaceNet

+ (AFHTTPRequestOperation *)searchPlaceWithName:(NSString *)name
                                     pageNumber:(NSInteger)page
                                       pageSize:(NSInteger)size
                                   successBlock:(httpSuccessBlock)successBlock
                                      failBlock:(httpFailBlock)failBlock
{
    NSString *url = [[NSString alloc] initWithFormat:@"%@/place/search",[self baseUrl]];
    NSDictionary *param = @{@"name":name,
                            @"page_number":[NSNumber numberWithInteger:page],
                            @"page_size":[NSNumber numberWithInteger:size]};
    AFHTTPRequestOperation *operation = [[self manager] GET:url parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        successBlock (operation,responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failBlock (operation,error);
    }];
    return operation;
}

+ (AFHTTPRequestOperation *)getPlaceActivityWithPlaceId:(UInt64)placeId
                                             pageNumber:(NSInteger)pageNumber
                                               pageSize:(NSInteger)pageSize
                                           successBlock:(httpSuccessBlock)successBlock
                                              failBlock:(httpFailBlock)failBlock
{
    NSString *url = [[NSString alloc] initWithFormat:@"%@/place_activity/paginate",[self baseUrl]];
    
    NSDictionary *param = @{@"token":[self token],
                            @"place_id":@(placeId),
                            @"page_number":@(pageNumber),
                            @"page_size":@(pageSize)};
    AFHTTPRequestOperation *operation = [[self manager] GET:url parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        successBlock (operation,responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failBlock (operation,error);
    }];
    return operation;
}

+ (AFHTTPRequestOperation *)getPlacePhotoWithPlaceId:(UInt64)placeId
                                          pageNumber:(NSInteger)pageNumber
                                            pageSize:(NSInteger)pageSize
                                        successBlock:(httpSuccessBlock)successBlock
                                           failBlock:(httpFailBlock)failBlock
{
    NSString *url = [[NSString alloc] initWithFormat:@"%@/place_photo/paginate",[self baseUrl]];
    
    NSDictionary *param = @{@"token":[self token],
                            @"place_id":@(placeId),
                            @"page_number":@(pageNumber),
                            @"page_size":@(pageSize)};
    AFHTTPRequestOperation *operation = [[self manager] GET:url parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        successBlock (operation,responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failBlock (operation,error);
    }];
    return operation;
}

@end
